<?php

class Main extends CI_Controller{

	function __construct(){
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		$this->user_authentication->logged_in('dashboard/main', 'member');
	}

	function index($menu="home"){
		$this->data['menu'] = $menu;
		$this->load->view('homepage/main', $this->data);
	}
	
	function login(){
		$this->load->library('form_validation');
		
		$this->form_validation->set_rules('user_name_login', 'username', 'required');
		$this->form_validation->set_rules('user_password_login', 'password', 'required');
		
		$this->form_validation->set_message('required', '%s harus diisi');
		
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		$this->data['menu'] = 'login';
		
		if ($this->form_validation->run() == false){
			$this->data['error'] = validation_errors();
			$this->load->view('homepage/main', $this->data);
		}else{
			$user_name = $_REQUEST['user_name_login'];
			$user_password = $_REQUEST['user_password_login'];
			$this->load->model('m_user');
			$user = $this->m_user->get_user($user_name,$user_password);
			if($user->num_rows()>0){
				$member = $user->row_array();
				if($member['user_status'] == '0'){
					$this->session->set_userdata('payment', $member);
					$this->data['pricing'] = $member['package_type'];
					$this->data['menu'] = 'payment_process';
					$this->data['confirm'] = 'Pembayaran belum dilakukan';
					$this->load->view('homepage/main', $this->data);
				}else{
					$this->session->set_userdata('member', $member);
					redirect('dashboard/main');
				}
			}else{
				$this->data['error'] = '<div class="error">Username atau password salah</div>';
				$this->load->view('homepage/main', $this->data);
			}
		}
	}
	
	function get_request(){
		$this->library->request_token();
	}
}